package com.ias.agdis_r.activity.setting;

import android.app.ActionBar;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.activity.BaseKeyActivity;
import com.ias.agdis_r.bean.other.GpsInfoBean;
import com.ias.agdis_r.manager.JavaBeanManager;
import com.ias.agdis_r.util.sdcard.WriteLog;

/**
 * GPS详情界面
 * @author guoxr
 *
 */
public class GPSDetailActivity extends BaseKeyActivity {

	private TextView txt_utc, txt_wd, txt_jd, txt_xdwysd, txt_ds;
	private Handler handler = new Handler();
	private Runnable updateThread = new Runnable() {
		public void run() {
			initUI();
			// 间隔1秒，循环执行
			handler.postDelayed(updateThread, 1000);
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gpsdetail);
		initActionBar();
		initView();
		handler.post(updateThread);
	}

	private void initUI() {
		GpsInfoBean info = JavaBeanManager.getInstance().getLastGpsInfo();
		if (info != null) {
			txt_utc.setText(info.getGpsTime());
			txt_wd.setText(info.getLatitude());
			txt_jd.setText(info.getLongitude());
			txt_xdwysd.setText(info.getGpsSpeed() + "");
			txt_ds.setText(info.getBear());
		}else {
			WriteLog.getInstance().writeDebugLog("GPSDetailActivity|info==null");
		}
	}

	private void initView() {
		Button button_back = (Button) findViewById(R.id.button_back);
		button_back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		txt_utc = (TextView) findViewById(R.id.txt_utc);
		txt_wd = (TextView) findViewById(R.id.txt_wd);
		txt_jd = (TextView) findViewById(R.id.txt_jd);
		txt_xdwysd = (TextView) findViewById(R.id.txt_xdwysd);
		txt_ds = (TextView) findViewById(R.id.txt_ds);
	}

	private void initActionBar() {
		ActionBar actionBar = getActionBar();
		actionBar.setCustomView(LayoutInflater.from(this).inflate(R.layout.actionbar_settings, null));
		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		actionBar.setDisplayShowCustomEnabled(true);
		TextView title = (TextView) findViewById(R.id.txt_title);
		title.setText(R.string.GPSDetailActivity);
		ImageView back = (ImageView) findViewById(R.id.actionbar_settings_back);
		back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		handler.removeCallbacks(updateThread);
	}

}
